From e2e5440b078b0bb56972ed8ba6fe1e5d7620cf72 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Tue, 16 Aug 2005 14:22:20 +0000 Subject: [PATCH] polymorphication --- ChangeLog | 23 +++++++++++ babl/babl-component.c | 44 ++++++++++---------- babl/babl-component.h | 2 +- babl/babl-conversion.c | 70 ++++++++++++++++---------------- babl/babl-conversion.h | 2 +- babl/babl-fish.c | 77 ++++++++++++++++++----------------- babl/babl-fish.h | 18 ++++----- babl/babl-format.c | 60 ++++++++++++++-------------- babl/babl-format.h | 2 +- babl/babl-image.c | 80 ++++++++++++++++++------------------- babl/babl-image.h | 19 ++++----- babl/babl-instance.h | 28 ++++++------- babl/babl-internal.h | 25 ++++++------ babl/babl-introspect.c | 6 +-- babl/babl-model.c | 46 ++++++++++----------- babl/babl-model.h | 2 +- babl/babl-pixel-format.c | 60 ++++++++++++++-------------- babl/babl-pixel-format.h | 2 +- babl/babl-sampling.c | 2 +- babl/babl-sampling.h | 6 +-- babl/babl-sanity.c | 8 ++-- babl/babl-type.c | 36 ++++++++--------- babl/babl-type.h | 2 +- tests/float_to_u8.c | 10 ++--- tests/grayscale_to_rgb.c | 10 ++--- tests/rgb_to_lab_to_rgb.c | 14 +++---- tests/rgb_to_ycbcr.c | 11 +++-- tests/rgb_to_ycbcr_to_rgb.c | 15 ++++--- tests/u8_to_float.c | 10 ++--- 29 files changed, 354 insertions(+), 336 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9263c3a..986fc0f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2005-08-16 Øyvind Kolås + + * babl/babl-component.[ch] + * babl/babl-conversion.[ch] + * babl/babl-fish.[ch] + * babl/babl-image.[ch] + * babl/babl-instance.h + * babl/babl-internal.h + * babl/babl-introspect.c + * babl/babl-model.[ch] + * babl/babl-pixel-format.[ch] + * babl/babl-sampling.[ch] + * babl/babl-sanity.c + * babl/babl-type.[ch] + * tests/float_to_u8.c + * tests/grayscale_to_rgb.c + * tests/rgb_to_lab_to_rgb.c + * tests/rgb_to_ycbcr.c + * tests/rgb_to_ycbcr_to_rgb.c + * tests/u8_to_float.c: Changed to use polymorph Babl * union's instead + of class specific structs in most cases, and in all cases for the + public API. + 2005-08-16 Øyvind Kolås * AUTHORS: Fixed spelling of Sven Neumann. diff --git a/babl/babl-component.c b/babl/babl-component.c index a591f8e..4f5d693 100644 --- a/babl/babl-component.c +++ b/babl/babl-component.c @@ -35,37 +35,37 @@ each_babl_component_destroy (Babl *babl, return 0; /* continue iterating */ } -static BablComponent * +static Babl * component_new (const char *name, int id, int luma, int chroma, int alpha) { - Babl *self; + Babl *babl; - self = babl_calloc (sizeof (BablComponent), 1); - self->class_type = BABL_COMPONENT; - self->instance.id = id; - self->instance.name = babl_strdup (name); - self->component.luma = luma; - self->component.chroma = chroma; - self->component.alpha = alpha; + babl = babl_calloc (sizeof (BablComponent), 1); + babl->class_type = BABL_COMPONENT; + babl->instance.id = id; + babl->instance.name = babl_strdup (name); + babl->component.luma = luma; + babl->component.chroma = chroma; + babl->component.alpha = alpha; - return (BablComponent*) self; + return babl; } -BablComponent * +Babl * babl_component_new (const char *name, ...) { va_list varg; - BablComponent *self; - int id = 0; - int luma = 0; - int chroma = 0; - int alpha = 0; - const char *arg=name; + Babl *babl; + int id = 0; + int luma = 0; + int chroma = 0; + int alpha = 0; + const char *arg=name; va_start (varg, name); @@ -136,17 +136,17 @@ babl_component_new (const char *name, va_end (varg); - self = component_new (name, id, luma, chroma, alpha); + babl = component_new (name, id, luma, chroma, alpha); - if ((BablComponent*) db_insert ((Babl*)self) == self) + if (db_insert (babl) == babl) { - return self; + return babl; } else { - each_babl_component_destroy ((Babl*)self, NULL); + each_babl_component_destroy (babl, NULL); return NULL; } } -BABL_CLASS_TEMPLATE(BablComponent, babl_component, "BablComponent") +BABL_CLASS_TEMPLATE (babl_component) diff --git a/babl/babl-component.h b/babl/babl-component.h index 17a1ee0..dc7c26a 100644 --- a/babl/babl-component.h +++ b/babl/babl-component.h @@ -21,6 +21,6 @@ #define _BABL_COMPONENT_H #include "babl-classes.h" -BABL_DEFINE_CLASS(BablComponent, babl_component) +BABL_DEFINE_CLASS (babl_component) #endif diff --git a/babl/babl-conversion.c b/babl/babl-conversion.c index f2385ff..9aa7f87 100644 --- a/babl/babl-conversion.c +++ b/babl/babl-conversion.c @@ -32,7 +32,7 @@ each_babl_conversion_destroy (Babl *babl, return 0; /* continue iterating */ } -static BablConversion * +static Babl * conversion_new (const char *name, int id, Babl *source, @@ -43,7 +43,7 @@ conversion_new (const char *name, BablFuncPlanar planar, BablFuncPlanarBit planar_bit) { - Babl *self = NULL; + Babl *babl = NULL; /* destination is of same type as source */ switch (source->class_type) @@ -51,15 +51,15 @@ conversion_new (const char *name, case BABL_TYPE: if (linear) { - self = babl_calloc (sizeof (BablConversionType), 1); - self->class_type = BABL_CONVERSION_TYPE; - self->conversion.function.linear = linear; + babl = babl_calloc (sizeof (BablConversionType), 1); + babl->class_type = BABL_CONVERSION_TYPE; + babl->conversion.function.linear = linear; } else if (planar) { - self = babl_calloc (sizeof (BablConversionTypePlanar), 1); - self->class_type = BABL_CONVERSION_TYPE_PLANAR; - self->conversion.function.planar = planar; + babl = babl_calloc (sizeof (BablConversionTypePlanar), 1); + babl->class_type = BABL_CONVERSION_TYPE_PLANAR; + babl->conversion.function.planar = planar; } else if (planar_bit) { @@ -83,9 +83,9 @@ conversion_new (const char *name, } else if (planar) { - self = babl_calloc (sizeof (BablConversionModelPlanar), 1); - self->class_type = BABL_CONVERSION_MODEL_PLANAR; - self->conversion.function.planar = planar; + babl = babl_calloc (sizeof (BablConversionModelPlanar), 1); + babl->class_type = BABL_CONVERSION_MODEL_PLANAR; + babl->conversion.function.planar = planar; } else if (planar_bit) { @@ -97,15 +97,15 @@ conversion_new (const char *name, case BABL_PIXEL_FORMAT: if (linear) { - self = babl_calloc (sizeof (BablConversionPixelFormat), 1); - self->class_type = BABL_CONVERSION_PIXEL_FORMAT; - self->conversion.function.linear = linear; + babl = babl_calloc (sizeof (BablConversionPixelFormat), 1); + babl->class_type = BABL_CONVERSION_PIXEL_FORMAT; + babl->conversion.function.linear = linear; } else if (planar) { - self = babl_calloc (sizeof (BablConversionPixelFormatPlanar), 1); - self->class_type = BABL_CONVERSION_PIXEL_FORMAT_PLANAR; - self->conversion.function.planar = planar; + babl = babl_calloc (sizeof (BablConversionPixelFormatPlanar), 1); + babl->class_type = BABL_CONVERSION_PIXEL_FORMAT_PLANAR; + babl->conversion.function.planar = planar; } else if (planar_bit) { @@ -116,31 +116,31 @@ conversion_new (const char *name, default: break; } - if (!self) + if (!babl) { babl_log ("%s(name='%s', ...): creation failed", __FUNCTION__, name); return NULL; } - self->instance.id = id; - self->instance.name = babl_strdup (name); - self->conversion.source = (union Babl*)source; - self->conversion.destination = (union Babl*)destination; - self->conversion.time_cost = time_cost; - self->conversion.loss = loss; + babl->instance.id = id; + babl->instance.name = babl_strdup (name); + babl->conversion.source = (union Babl*)source; + babl->conversion.destination = (union Babl*)destination; + babl->conversion.time_cost = time_cost; + babl->conversion.loss = loss; - babl_add_ptr_to_list ((void ***)&(source->type.from), self); - babl_add_ptr_to_list ((void ***)&(destination->type.to), self); + babl_add_ptr_to_list ((void ***)&(source->type.from), babl); + babl_add_ptr_to_list ((void ***)&(destination->type.to), babl); - return (BablConversion*)self; + return babl; } -BablConversion * +Babl * babl_conversion_new (const char *name, ...) { va_list varg; - BablConversion *self; + Babl *babl; int id = 0; Babl *source = NULL; @@ -226,18 +226,18 @@ babl_conversion_new (const char *name, assert (source); assert (destination); - self = conversion_new (name, id, - source, destination, time_cost, loss, linear, planar, planar_bit); + babl = conversion_new (name, id, source, destination, time_cost, loss, linear, + planar, planar_bit); - if ((BablConversion*) db_insert ( (Babl*)self) == self) + if (db_insert (babl) == babl) { - return self; + return babl; } else { - each_babl_conversion_destroy ( (Babl*)self, NULL); + each_babl_conversion_destroy (babl, NULL); return NULL; } } -BABL_CLASS_TEMPLATE(BablConversion, babl_conversion, "BablConversion") +BABL_CLASS_TEMPLATE (babl_conversion) diff --git a/babl/babl-conversion.h b/babl/babl-conversion.h index 214fde0..327de75 100644 --- a/babl/babl-conversion.h +++ b/babl/babl-conversion.h @@ -22,6 +22,6 @@ #include "babl-classes.h" -BABL_DEFINE_CLASS(BablConversion, babl_conversion) +BABL_DEFINE_CLASS (babl_conversion) #endif diff --git a/babl/babl-fish.c b/babl/babl-fish.c index d8d4a8a..76f9e8d 100644 --- a/babl/babl-fish.c +++ b/babl/babl-fish.c @@ -87,8 +87,8 @@ find_conversion (Babl *babl, { SearchData *sd = user_data; - if ((Babl*)babl->conversion.source == sd->source && - (Babl*)babl->conversion.destination == sd->destination) + if (BABL(babl->conversion.source) == sd->source && + BABL(babl->conversion.destination) == sd->destination) { sd->result = (BablConversion*)babl; return 1; @@ -96,26 +96,26 @@ find_conversion (Babl *babl, return 0; } -BablConversion *babl_conversion_find (Babl *source, - Babl *destination) +BablConversion *babl_conversion_find (void *source, + void *destination) { SearchData data; - data.source = source; - data.destination = destination; + data.source = BABL(source); + data.destination = BABL(destination); data.result = NULL; babl_conversion_each (find_conversion, &data); if (!data.result) { babl_log ("%s('%s', '%s'): failed, aborting", __FUNCTION__, - source->instance.name, destination->instance.name); + data.source->instance.name, data.destination->instance.name); exit (-1); return NULL; } return data.result; } -BablFish * +Babl * babl_fish_reference_new (Babl *source, Babl *destination) { @@ -133,31 +133,31 @@ babl_fish_reference_new (Babl *source, babl->reference_fish.type_to_double = babl_conversion_find ( - (Babl*)source->pixel_format.type[0], - (Babl*)babl_type_id (BABL_DOUBLE) + source->pixel_format.type[0], + babl_type_id (BABL_DOUBLE) ); babl->reference_fish.model_to_rgba = babl_conversion_find ( - (Babl*)source->pixel_format.model[0], - (Babl*)babl_model_id (BABL_RGBA) + source->pixel_format.model[0], + babl_model_id (BABL_RGBA) ); babl->reference_fish.rgba_to_model = babl_conversion_find ( - (Babl*)babl_model_id (BABL_RGBA), - (Babl*)destination->pixel_format.model[0] + babl_model_id (BABL_RGBA), + destination->pixel_format.model[0] ); babl->reference_fish.double_to_type = babl_conversion_find ( - (Babl*)babl_type_id (BABL_DOUBLE), - (Babl*)destination->pixel_format.type[0] + babl_type_id (BABL_DOUBLE), + destination->pixel_format.type[0] ); if (db_insert (babl) == babl) { - return (BablFish*)babl; + return babl; } else { @@ -174,10 +174,10 @@ babl_fish_reference_new (Babl *source, babl_add_ptr_to_list ((void ***)&(source->type.from), babl); babl_add_ptr_to_list ((void ***)&(destination->type.to), babl); */ - return (BablFish*) babl; + return babl; } -BablFish * +Babl * babl_fish (Babl *source, Babl *destination) { @@ -197,9 +197,9 @@ babl_fish_process (BablFish *babl_fish, int n) { Babl *babl; - BablImage *imageA; - BablImage *imageB; - BablImage *imageC; + Babl *imageA; + Babl *imageB; + Babl *imageC; fooA = babl_malloc(sizeof (double) * n * 4); fooB = babl_malloc(sizeof (double) * n * 4); @@ -225,18 +225,17 @@ babl_fish_process (BablFish *babl_fish, /* calculate planar representation of fooA, and fooB */ - imageA = babl_image_new_from_linear (fooA, - (Babl*) ((BablPixelFormat*) babl->fish.source)->model[0]); - imageB = babl_image_new_from_linear (fooB, (Babl*)babl_model_id (BABL_RGBA)); + imageA = babl_image_new_from_linear (fooA, BABL(BABL((babl->fish.source)) -> pixel_format.model[0])); + imageB = babl_image_new_from_linear (fooB, babl_model_id (BABL_RGBA)); /* transform fooA into fooB fooB is rgba double */ ((BablConversion*)(babl->reference_fish.model_to_rgba))->function.planar( - imageA->bands, - imageA->data, - imageA->pitch, - imageB->bands, - imageB->data, - imageB->pitch, + imageA->image.bands, + imageA->image.data, + imageA->image.pitch, + imageB->image.bands, + imageB->image.data, + imageB->image.pitch, n); babl_free (imageA); babl_free (imageB); @@ -244,16 +243,16 @@ babl_fish_process (BablFish *babl_fish, /* calculate planar representation of fooC */ /* transform fooB into fooC fooC is ???? double */ - imageB = babl_image_new_from_linear (fooB, (Babl*)babl_model_id (BABL_RGBA)); - imageC = babl_image_new_from_linear (fooA, (Babl*)((BablPixelFormat*)babl->fish.destination)->model[0]); + imageB = babl_image_new_from_linear (fooB, babl_model_id (BABL_RGBA)); + imageC = babl_image_new_from_linear (fooA, BABL(BABL((babl->fish.destination))->pixel_format.model[0])); ((BablConversion*)(babl->reference_fish.rgba_to_model))->function.planar( - imageB->bands, - imageB->data, - imageB->pitch, - imageC->bands, - imageC->data, - imageC->pitch, + imageB->image.bands, + imageB->image.data, + imageB->image.pitch, + imageC->image.bands, + imageC->image.data, + imageC->image.pitch, n); diff --git a/babl/babl-fish.h b/babl/babl-fish.h index 6e1651e..087146a 100644 --- a/babl/babl-fish.h +++ b/babl/babl-fish.h @@ -22,13 +22,9 @@ #include "babl-classes.h" -BABL_DEFINE_CLASS_NO_NEW_NO_ID(BablFish, babl_fish) +BABL_DEFINE_CLASS_NO_NEW_NO_ID(babl_fish) -BablFish * -babl_fish_new (Babl *source, - Babl *destination); - -BablFish * +Babl * babl_fish (Babl *source, Babl *destination); @@ -37,15 +33,15 @@ babl_fish (Babl *source, * allowed as well as BablImage objects in their place */ int -babl_fish_process (BablFish *babl_fish, - void *source, - void *destination, - int n); +babl_fish_process (Babl *babl_fish, + void *source, + void *destination, + int n); /* whether the BablFish needs a BablImage to do the processing, * or void * are sufficient. */ int -babl_fish_needs_image (BablFish *babl_dish); +babl_fish_needs_image (Babl *babl_fish); #endif diff --git a/babl/babl-format.c b/babl/babl-format.c index 8350213..14c60c2 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -44,7 +44,7 @@ each_babl_pixel_format_destroy (Babl *babl, return 0; /* continue iterating */ } -static BablPixelFormat * +static Babl * pixel_format_new (const char *name, int id, int planar, @@ -54,44 +54,44 @@ pixel_format_new (const char *name, BablSampling **sampling, BablType **type) { - Babl *self; + Babl *babl; int band; - self = babl_calloc (sizeof (BablPixelFormat), 1); + babl = babl_calloc (sizeof (BablPixelFormat), 1); - self->class_type = BABL_PIXEL_FORMAT; - self->instance.id = id; - self->instance.name = babl_strdup (name); + babl->class_type = BABL_PIXEL_FORMAT; + babl->instance.id = id; + babl->instance.name = babl_strdup (name); - self->pixel_format.bands = bands; - self->pixel_format.planar = planar; + babl->pixel_format.bands = bands; + babl->pixel_format.planar = planar; - self->pixel_format.model = babl_malloc (sizeof (BablModel*) * (bands+1)); - self->pixel_format.component = babl_malloc (sizeof (BablComponent*) * (bands+1)); - self->pixel_format.type = babl_malloc (sizeof (BablType*) * (bands+1)); - self->pixel_format.sampling = babl_malloc (sizeof (BablSampling*) * (bands+1)); + babl->pixel_format.model = babl_malloc (sizeof (BablModel*) * (bands+1)); + babl->pixel_format.component = babl_malloc (sizeof (BablComponent*) * (bands+1)); + babl->pixel_format.type = babl_malloc (sizeof (BablType*) * (bands+1)); + babl->pixel_format.sampling = babl_malloc (sizeof (BablSampling*) * (bands+1)); for (band=0; band < bands; band++) { - self->pixel_format.model[band] = model[band]; - self->pixel_format.component[band] = component[band]; - self->pixel_format.type[band] = type[band]; - self->pixel_format.sampling[band] = sampling[band]; + babl->pixel_format.model[band] = model[band]; + babl->pixel_format.component[band] = component[band]; + babl->pixel_format.type[band] = type[band]; + babl->pixel_format.sampling[band] = sampling[band]; } - self->pixel_format.model[band] = NULL; - self->pixel_format.component[band] = NULL; - self->pixel_format.type[band] = NULL; - self->pixel_format.sampling[band] = NULL; + babl->pixel_format.model[band] = NULL; + babl->pixel_format.component[band] = NULL; + babl->pixel_format.type[band] = NULL; + babl->pixel_format.sampling[band] = NULL; - return (BablPixelFormat*)self; + return babl; } -BablPixelFormat * +Babl * babl_pixel_format_new (const char *name, ...) { va_list varg; - BablPixelFormat *self; + Babl *babl; int id = 0; int planar = 0; int bands = 0; @@ -100,8 +100,8 @@ babl_pixel_format_new (const char *name, BablSampling *sampling [BABL_MAX_BANDS]; BablType *type [BABL_MAX_BANDS]; - BablSampling *current_sampling = babl_sampling (1,1); - BablType *current_type = babl_type_id (BABL_U8); + BablSampling *current_sampling = (BablSampling*) babl_sampling (1,1); + BablType *current_type = (BablType*) babl_type_id (BABL_U8); BablModel *current_model = NULL; const char *arg = name; @@ -193,21 +193,21 @@ babl_pixel_format_new (const char *name, va_end (varg); - self = pixel_format_new (name, id, + babl = pixel_format_new (name, id, planar, bands, model, component, sampling, type); - if ((BablPixelFormat*) db_insert ((Babl*)self) == self) + if (db_insert (babl) == babl) { - return self; + return babl; } else { - each_babl_pixel_format_destroy ((Babl*)self, NULL); + each_babl_pixel_format_destroy (babl, NULL); return NULL; } } -BABL_CLASS_TEMPLATE (BablPixelFormat, babl_pixel_format, "BablPixelFormat") +BABL_CLASS_TEMPLATE (babl_pixel_format) diff --git a/babl/babl-format.h b/babl/babl-format.h index a9d7977..b43d9c4 100644 --- a/babl/babl-format.h +++ b/babl/babl-format.h @@ -21,6 +21,6 @@ #define _BABL_PIXEL_FORMAT_H #include "babl-classes.h" -BABL_DEFINE_CLASS(BablPixelFormat, babl_pixel_format) +BABL_DEFINE_CLASS (babl_pixel_format) #endif diff --git a/babl/babl-image.c b/babl/babl-image.c index 48f470d..8dc132d 100644 --- a/babl/babl-image.c +++ b/babl/babl-image.c @@ -40,55 +40,55 @@ each_babl_image_destroy (Babl *babl, } #endif -static BablImage * +static Babl * image_new (int bands, BablComponent **component, void **data, int *pitch, int *stride) { - Babl *self; + Babl *babl; int band; - self = babl_calloc ( + babl = babl_calloc ( sizeof (BablImage) + sizeof (BablComponent*) * (bands+1) + sizeof (void*) * (bands+1) + sizeof (int) * (bands+1) + sizeof (int) * (bands+1),1); - self->image.component = ((void *)self) + sizeof (BablImage); - self->image.data = ((void *)self->image.component) + sizeof (BablComponent*) * (bands+1); - self->image.pitch = ((void *)self->image.data) + sizeof (void*) * (bands+1); - self->image.stride = ((void *)self->image.pitch) + sizeof (int) * (bands+1); -/*self->image.foo = ((void *)self->image.stride) + sizeof (int) * (bands+1);*/ + babl->image.component = ((void *)babl) + sizeof (BablImage); + babl->image.data = ((void *)babl->image.component) + sizeof (BablComponent*) * (bands+1); + babl->image.pitch = ((void *)babl->image.data) + sizeof (void*) * (bands+1); + babl->image.stride = ((void *)babl->image.pitch) + sizeof (int) * (bands+1); +/*babl->image.foo = ((void *)babl->image.stride) + sizeof (int) * (bands+1);*/ - self->class_type = BABL_IMAGE; - self->instance.id = 0; - self->instance.name = "babl image"; + babl->class_type = BABL_IMAGE; + babl->instance.id = 0; + babl->instance.name = "babl image"; - self->image.bands = bands; + babl->image.bands = bands; for (band=0; band < bands; band++) { - self->image.component[band] = component[band]; - self->image.data[band] = data[band]; - self->image.pitch[band] = pitch[band]; - self->image.stride[band] = stride[band]; + babl->image.component[band] = component[band]; + babl->image.data[band] = data[band]; + babl->image.pitch[band] = pitch[band]; + babl->image.stride[band] = stride[band]; } - self->image.component[band] = NULL; - self->image.data[band] = NULL; - self->image.pitch[band] = 0; - self->image.stride[band] = 0; + babl->image.component[band] = NULL; + babl->image.data[band] = NULL; + babl->image.pitch[band] = 0; + babl->image.stride[band] = 0; - return (BablImage*) self; + return babl; } -BablImage * +Babl * babl_image_new_from_linear (void *buffer, - Babl *babl) + Babl *format) { - BablImage *self; + Babl *babl; int band; BablComponent *component [BABL_MAX_BANDS]; void *data [BABL_MAX_BANDS]; @@ -98,20 +98,20 @@ babl_image_new_from_linear (void *buffer, int offset=0; int calc_pitch=0; - switch (babl->class_type) + switch (format->class_type) { case BABL_PIXEL_FORMAT: - for (band=0; band < babl->pixel_format.bands; band++) + for (band=0; band < format->pixel_format.bands; band++) { - BablType *type = babl->pixel_format.type[band]; + BablType *type = format->pixel_format.type[band]; calc_pitch += (type->bits / 8); } - for (band=0; band < babl->pixel_format.bands; band++) + for (band=0; band < format->pixel_format.bands; band++) { - BablType *type = babl->pixel_format.type[band]; + BablType *type = format->pixel_format.type[band]; - component[band] = babl->pixel_format.component[band]; + component[band] = format->pixel_format.component[band]; data[band] = buffer + offset; pitch[band] = calc_pitch; stride[band] = 0; @@ -120,14 +120,14 @@ babl_image_new_from_linear (void *buffer, } break; case BABL_MODEL: - for (band=0; band < babl->model.components; band++) + for (band=0; band < format->model.components; band++) { calc_pitch += (64 / 8); } - for (band=0; band < babl->model.components; band++) + for (band=0; band < format->model.components; band++) { - component[band] = babl->model.component[band]; + component[band] = format->model.component[band]; data[band] = buffer + offset; pitch[band] = calc_pitch; stride[band] = 0; @@ -140,16 +140,16 @@ babl_image_new_from_linear (void *buffer, break; } - self = image_new (babl->model.components, component, data, pitch, stride); - return self; + babl = image_new (format->model.components, component, data, pitch, stride); + return babl; } -BablImage * +Babl * babl_image_new (void *first, ...) { va_list varg; - BablImage *self; + Babl *babl; int bands = 0; BablComponent *component [BABL_MAX_BANDS]; void *data [BABL_MAX_BANDS]; @@ -183,7 +183,7 @@ babl_image_new (void *first, } else { - new_component = babl_component (arg); + new_component = (BablComponent*)babl_component (arg); } component [bands] = new_component; @@ -204,9 +204,9 @@ babl_image_new (void *first, va_end (varg); - self = image_new (bands, component, data, pitch, stride); + babl = image_new (bands, component, data, pitch, stride); - return self; + return babl; } void diff --git a/babl/babl-image.h b/babl/babl-image.h index 50b351c..fc33e0e 100644 --- a/babl/babl-image.h +++ b/babl/babl-image.h @@ -22,18 +22,19 @@ #include "babl-classes.h" -void babl_image_init (void); -void babl_image_introspect (void); -void babl_image_each (BablEachFunction each_fun, - void *user_data); -void babl_image_destroy (void); -BablImage * babl_image_new (void *first_component, +void babl_image_init (void); +void babl_image_introspect (void); +void babl_image_each (BablEachFunction each_fun, + void *user_data); +void babl_image_destroy (void); +Babl * babl_image_new (void *first_component, ...); -/* create a new BablImage based on a packed BablPixelFormat (or BablModel assumed to - * use only doubles). +/* create a new BablImage based on a packed BablPixelFormat (or BablModel which + * is a virtual pixelformat based on the BablModel using only doubles in the + * order they are listed in the model. */ -BablImage * +Babl * babl_image_new_from_linear (void *buffer, Babl *format); #endif diff --git a/babl/babl-instance.h b/babl/babl-instance.h index 3869787..cfd7ff2 100644 --- a/babl/babl-instance.h +++ b/babl/babl-instance.h @@ -11,21 +11,21 @@ const char *babl_class_name (BablClassType klass); * headers to a minimum, only the ones overriding the basic api with * custom ways of construction. */ -#define BABL_DEFINE_CLASS(TypeName, type_name) \ +#define BABL_DEFINE_CLASS(type_name) \ \ -void type_name##_init (void); \ -void type_name##_destroy (void); \ -void type_name##_each (BablEachFunction each_fun, \ - void *user_data); \ -TypeName * type_name (const char *name); \ -TypeName * type_name##_id (int id); \ -TypeName * type_name##_new (const char *name, \ - ...); -#define BABL_DEFINE_CLASS_NO_NEW_NO_ID(TypeName, type_name) \ +void type_name##_init (void); \ +void type_name##_destroy (void); \ +void type_name##_each (BablEachFunction each_fun, \ + void *user_data); \ +Babl * type_name (const char *name); \ +Babl * type_name##_id (int id); \ +Babl * type_name##_new (const char *name, \ + ...); +#define BABL_DEFINE_CLASS_NO_NEW_NO_ID(type_name) \ \ -void type_name##_init (void); \ -void type_name##_destroy (void); \ -void type_name##_each (BablEachFunction each_fun, \ - void *user_data); +void type_name##_init (void); \ +void type_name##_destroy (void); \ +void type_name##_each (BablEachFunction each_fun, \ + void *user_data); #endif diff --git a/babl/babl-internal.h b/babl/babl-internal.h index 5426de1..64b2b00 100644 --- a/babl/babl-internal.h +++ b/babl/babl-internal.h @@ -47,30 +47,30 @@ type_name##_each (BablEachFunction each_fun, \ db_each (each_fun, user_data); \ } \ -#define BABL_DEFINE_LOOKUP_BY_ID(TypeName, type_name) \ -TypeName * \ +#define BABL_DEFINE_LOOKUP_BY_ID(type_name) \ +Babl * \ type_name##_id (int id) \ { \ - return (TypeName*) db_exist (id, NULL); \ + return db_exist (id, NULL); \ } -#define BABL_DEFINE_LOOKUP_BY_NAME(TypeName, type_name) \ -TypeName * \ +#define BABL_DEFINE_LOOKUP_BY_NAME(type_name) \ +Babl * \ type_name (const char *name) \ { \ - TypeName *ret; \ + Babl *babl; \ \ if (babl_hmpf_on_name_lookups) \ { \ babl_log ("%s(\"%s\"): hmpf!", __FUNCTION__, name); \ } \ - ret = (TypeName*) db_exist (0, name); \ + babl = db_exist (0, name); \ \ - if (!ret) \ + if (!babl) \ { \ babl_log ("%s(\"%s\"): not found", __FUNCTION__, name); \ } \ - return ret; \ + return babl; \ } #define BABL_DEFINE_INIT(type_name) \ @@ -88,12 +88,13 @@ type_name##_destroy (void) \ db_destroy (); \ } -#define BABL_CLASS_TEMPLATE(TypeName, type_name, type_string) \ +#define BABL_CLASS_TEMPLATE(type_name) \ BABL_DEFINE_INIT (type_name) \ BABL_DEFINE_DESTROY (type_name) \ -BABL_DEFINE_LOOKUP_BY_NAME (TypeName, type_name) \ +BABL_DEFINE_LOOKUP_BY_NAME (type_name) \ BABL_DEFINE_EACH (type_name) \ -BABL_DEFINE_LOOKUP_BY_ID (TypeName, type_name) +BABL_DEFINE_LOOKUP_BY_ID (type_name) +#define BABL(obj) ((Babl*)(obj)) #endif diff --git a/babl/babl-introspect.c b/babl/babl-introspect.c index 6ab5b28..36b35fd 100644 --- a/babl/babl-introspect.c +++ b/babl/babl-introspect.c @@ -113,7 +113,7 @@ model_introspect (Babl *babl) for (i=0; i< babl->model.components; i++) { babl_log ("\t\tindex[%i] = '%s'", - i, ((Babl*)babl->model.component[i])->instance.name ); + i, BABL(babl->model.component[i])->instance.name ); } } @@ -144,8 +144,8 @@ pixel_format_introspect (Babl *babl) for (i=0; i< babl->pixel_format.bands; i++) { babl_log ("\t\tband[%i] type='%s' component='%s'", - i, ( (Babl*)(babl->pixel_format.type[i] ))->instance.name, - ( (Babl*)(babl->pixel_format.component[i]))->instance.name); + i, ( BABL(babl->pixel_format.type[i] ))->instance.name, + ( BABL(babl->pixel_format.component[i]))->instance.name); } } diff --git a/babl/babl-model.c b/babl/babl-model.c index c957409..0218090 100644 --- a/babl/babl-model.c +++ b/babl/babl-model.c @@ -38,42 +38,42 @@ each_babl_model_destroy (Babl *babl, #define BABL_MAX_COMPONENTS 32 -static BablModel * +static Babl * model_new (const char *name, int id, int components, BablComponent **component) { - Babl *self; + Babl *babl; int i; - self = babl_calloc (sizeof (BablModel), 1); + babl = babl_calloc (sizeof (BablModel), 1); - self->class_type = BABL_MODEL; - self->instance.id = id; - self->instance.name = babl_strdup (name); - self->model.components = components; - self->model.component = babl_malloc (sizeof (BablComponent*) * (components+1)); + babl->class_type = BABL_MODEL; + babl->instance.id = id; + babl->instance.name = babl_strdup (name); + babl->model.components = components; + babl->model.component = babl_malloc (sizeof (BablComponent*) * (components+1)); for (i=0; i < components; i++) { - self->model.component[i] = component[i]; + babl->model.component[i] = component[i]; } - self->model.component[i] = NULL; + babl->model.component[i] = NULL; - return (BablModel*)self; + return babl; } -BablModel * +Babl * babl_model_new (const char *name, ...) { - va_list varg; - BablModel *self; - int id = 0; - int components = 0; - BablComponent *band_component [BABL_MAX_COMPONENTS]; - const char *arg=name; + va_list varg; + Babl *babl; + int id = 0; + int components = 0; + BablComponent *band_component [BABL_MAX_COMPONENTS]; + const char *arg=name; va_start (varg, name); @@ -142,17 +142,17 @@ babl_model_new (const char *name, va_end (varg); - self = model_new (name, id, components, band_component); + babl = model_new (name, id, components, band_component); - if ((BablModel*) db_insert ((Babl*)self) == self) + if (db_insert (babl) == babl) { - return self; + return babl; } else { - each_babl_model_destroy ((Babl*)self, NULL); + each_babl_model_destroy (babl, NULL); return NULL; } } -BABL_CLASS_TEMPLATE (BablModel, babl_model, "BablModel") +BABL_CLASS_TEMPLATE (babl_model) diff --git a/babl/babl-model.h b/babl/babl-model.h index 31121ea..d31cbe5 100644 --- a/babl/babl-model.h +++ b/babl/babl-model.h @@ -21,6 +21,6 @@ #define _BABL_pixel_format_H #include "babl-classes.h" -BABL_DEFINE_CLASS(BablModel, babl_model) +BABL_DEFINE_CLASS (babl_model) #endif diff --git a/babl/babl-pixel-format.c b/babl/babl-pixel-format.c index 8350213..14c60c2 100644 --- a/babl/babl-pixel-format.c +++ b/babl/babl-pixel-format.c @@ -44,7 +44,7 @@ each_babl_pixel_format_destroy (Babl *babl, return 0; /* continue iterating */ } -static BablPixelFormat * +static Babl * pixel_format_new (const char *name, int id, int planar, @@ -54,44 +54,44 @@ pixel_format_new (const char *name, BablSampling **sampling, BablType **type) { - Babl *self; + Babl *babl; int band; - self = babl_calloc (sizeof (BablPixelFormat), 1); + babl = babl_calloc (sizeof (BablPixelFormat), 1); - self->class_type = BABL_PIXEL_FORMAT; - self->instance.id = id; - self->instance.name = babl_strdup (name); + babl->class_type = BABL_PIXEL_FORMAT; + babl->instance.id = id; + babl->instance.name = babl_strdup (name); - self->pixel_format.bands = bands; - self->pixel_format.planar = planar; + babl->pixel_format.bands = bands; + babl->pixel_format.planar = planar; - self->pixel_format.model = babl_malloc (sizeof (BablModel*) * (bands+1)); - self->pixel_format.component = babl_malloc (sizeof (BablComponent*) * (bands+1)); - self->pixel_format.type = babl_malloc (sizeof (BablType*) * (bands+1)); - self->pixel_format.sampling = babl_malloc (sizeof (BablSampling*) * (bands+1)); + babl->pixel_format.model = babl_malloc (sizeof (BablModel*) * (bands+1)); + babl->pixel_format.component = babl_malloc (sizeof (BablComponent*) * (bands+1)); + babl->pixel_format.type = babl_malloc (sizeof (BablType*) * (bands+1)); + babl->pixel_format.sampling = babl_malloc (sizeof (BablSampling*) * (bands+1)); for (band=0; band < bands; band++) { - self->pixel_format.model[band] = model[band]; - self->pixel_format.component[band] = component[band]; - self->pixel_format.type[band] = type[band]; - self->pixel_format.sampling[band] = sampling[band]; + babl->pixel_format.model[band] = model[band]; + babl->pixel_format.component[band] = component[band]; + babl->pixel_format.type[band] = type[band]; + babl->pixel_format.sampling[band] = sampling[band]; } - self->pixel_format.model[band] = NULL; - self->pixel_format.component[band] = NULL; - self->pixel_format.type[band] = NULL; - self->pixel_format.sampling[band] = NULL; + babl->pixel_format.model[band] = NULL; + babl->pixel_format.component[band] = NULL; + babl->pixel_format.type[band] = NULL; + babl->pixel_format.sampling[band] = NULL; - return (BablPixelFormat*)self; + return babl; } -BablPixelFormat * +Babl * babl_pixel_format_new (const char *name, ...) { va_list varg; - BablPixelFormat *self; + Babl *babl; int id = 0; int planar = 0; int bands = 0; @@ -100,8 +100,8 @@ babl_pixel_format_new (const char *name, BablSampling *sampling [BABL_MAX_BANDS]; BablType *type [BABL_MAX_BANDS]; - BablSampling *current_sampling = babl_sampling (1,1); - BablType *current_type = babl_type_id (BABL_U8); + BablSampling *current_sampling = (BablSampling*) babl_sampling (1,1); + BablType *current_type = (BablType*) babl_type_id (BABL_U8); BablModel *current_model = NULL; const char *arg = name; @@ -193,21 +193,21 @@ babl_pixel_format_new (const char *name, va_end (varg); - self = pixel_format_new (name, id, + babl = pixel_format_new (name, id, planar, bands, model, component, sampling, type); - if ((BablPixelFormat*) db_insert ((Babl*)self) == self) + if (db_insert (babl) == babl) { - return self; + return babl; } else { - each_babl_pixel_format_destroy ((Babl*)self, NULL); + each_babl_pixel_format_destroy (babl, NULL); return NULL; } } -BABL_CLASS_TEMPLATE (BablPixelFormat, babl_pixel_format, "BablPixelFormat") +BABL_CLASS_TEMPLATE (babl_pixel_format) diff --git a/babl/babl-pixel-format.h b/babl/babl-pixel-format.h index a9d7977..b43d9c4 100644 --- a/babl/babl-pixel-format.h +++ b/babl/babl-pixel-format.h @@ -21,6 +21,6 @@ #define _BABL_PIXEL_FORMAT_H #include "babl-classes.h" -BABL_DEFINE_CLASS(BablPixelFormat, babl_pixel_format) +BABL_DEFINE_CLASS (babl_pixel_format) #endif diff --git a/babl/babl-sampling.c b/babl/babl-sampling.c index 7bd2f86..a5e813d 100644 --- a/babl/babl-sampling.c +++ b/babl/babl-sampling.c @@ -63,7 +63,7 @@ babl_sampling_each (BablEachFunction each_fun, for (vertical=VERTICAL_MIN; vertical<=VERTICAL_MAX; vertical++) { int index= (vertical-VERTICAL_MIN) * VERTICAL_MAX + (horizontal - HORIZONTAL_MIN); - if (each_fun ((Babl*) &(db[index]), user_data)) + if (each_fun (BABL (&db[index]), user_data)) return; } } diff --git a/babl/babl-sampling.h b/babl/babl-sampling.h index 5304c3f..6bc917b 100644 --- a/babl/babl-sampling.h +++ b/babl/babl-sampling.h @@ -22,7 +22,7 @@ #include "babl-classes.h" -BABL_DEFINE_CLASS_NO_NEW_NO_ID(BablSampling, babl_sampling) -BablSampling * babl_sampling (int horizontal, - int vertical); +BABL_DEFINE_CLASS_NO_NEW_NO_ID(babl_sampling) +Babl * babl_sampling (int horizontal, + int vertical); #endif diff --git a/babl/babl-sanity.c b/babl/babl-sanity.c index db58dc8..271f84e 100644 --- a/babl/babl-sanity.c +++ b/babl/babl-sanity.c @@ -47,7 +47,7 @@ type_sanity (Babl *babl, while (ptr && NULL!=*ptr) { - if (babl_conversion_destination ((Babl *)(*ptr)) == (Babl*)babl_type_id (BABL_DOUBLE)) + if (babl_conversion_destination ((Babl *)(*ptr)) == babl_type_id (BABL_DOUBLE)) { ok = 1; break; @@ -67,7 +67,7 @@ type_sanity (Babl *babl, while (ptr && NULL!=*ptr) { - if (babl_conversion_source ((Babl *)(*ptr)) == (Babl*)babl_type_id (BABL_DOUBLE)) + if (babl_conversion_source ((Babl *)(*ptr)) == babl_type_id (BABL_DOUBLE)) { ok = 1; break; @@ -99,7 +99,7 @@ model_sanity (Babl *babl, while (ptr && NULL!=*ptr) { - if (babl_conversion_destination ((Babl *)(*ptr)) == (Babl*)babl_model_id (BABL_RGBA)) + if (babl_conversion_destination ((Babl *)(*ptr)) == babl_model_id (BABL_RGBA)) { ok = 1; break; @@ -119,7 +119,7 @@ model_sanity (Babl *babl, while (ptr && NULL!=*ptr) { - if (babl_conversion_source ((Babl *)(*ptr)) == (Babl*)babl_model_id (BABL_RGBA)) + if (babl_conversion_source ((Babl *)(*ptr)) == babl_model_id (BABL_RGBA)) { ok = 1; break; diff --git a/babl/babl-type.c b/babl/babl-type.c index 4db95bd..15ec851 100644 --- a/babl/babl-type.c +++ b/babl/babl-type.c @@ -37,33 +37,33 @@ each_babl_type_destroy (Babl *babl, } -static BablType * +static Babl * type_new (const char *name, int id, int bits) { - Babl *self; + Babl *babl; assert (bits != 0); assert (bits % 8 == 0); - self = babl_calloc (sizeof (BablType), 1); - self->class_type = BABL_TYPE; - self->instance.id = id; - self->instance.name = babl_strdup (name); - self->type.bits = bits; + babl = babl_calloc (sizeof (BablType), 1); + babl->class_type = BABL_TYPE; + babl->instance.id = id; + babl->instance.name = babl_strdup (name); + babl->type.bits = bits; - return (BablType*)self; + return babl; } -BablType * +Babl * babl_type_new (const char *name, ...) { - va_list varg; - BablType *self; - int id = 0; - int bits = 0; + va_list varg; + Babl *babl; + int id = 0; + int bits = 0; const char *arg=name; @@ -103,17 +103,17 @@ babl_type_new (const char *name, va_end (varg); - self = type_new (name, id, bits); + babl = type_new (name, id, bits); - if ((BablType*) db_insert ((Babl*)self) == self) + if (db_insert (babl) == babl) { - return self; + return babl; } else { - each_babl_type_destroy ((Babl*)self, NULL); + each_babl_type_destroy (babl, NULL); return NULL; } } -BABL_CLASS_TEMPLATE (BablType, babl_type, "BablType") +BABL_CLASS_TEMPLATE (babl_type) diff --git a/babl/babl-type.h b/babl/babl-type.h index 6b05fe8..f4417e3 100644 --- a/babl/babl-type.h +++ b/babl/babl-type.h @@ -21,6 +21,6 @@ #define _BABL_TYPE_H #include "babl-classes.h" -BABL_DEFINE_CLASS(BablType, babl_type) +BABL_DEFINE_CLASS (babl_type) #endif diff --git a/tests/float_to_u8.c b/tests/float_to_u8.c index 5f392e2..86b9e4d 100644 --- a/tests/float_to_u8.c +++ b/tests/float_to_u8.c @@ -46,20 +46,20 @@ unsigned char u8_ref_buf [BUFFER_LENGTH]= int test_float_to_rgb_u8 (void) { - BablFish *fish; - int i; - int OK=1; + Babl *fish; + int i; + int OK=1; fish = babl_fish ( - (Babl*) babl_pixel_format_new ( + babl_pixel_format_new ( "foo", babl_model ("grayscale"), babl_type ("float"), babl_component ("luminance"), NULL ), - (Babl*) babl_pixel_format_new ( + babl_pixel_format_new ( "bar", babl_model ("grayscale"), babl_type ("u8"), diff --git a/tests/grayscale_to_rgb.c b/tests/grayscale_to_rgb.c index deb9cac..367689d 100644 --- a/tests/grayscale_to_rgb.c +++ b/tests/grayscale_to_rgb.c @@ -32,20 +32,20 @@ float rgb_buf [PIXELS*3]; int test (void) { - BablFish *fish; - int i; - int OK=1; + Babl *fish; + int i; + int OK=1; fish = babl_fish ( - (Babl*) babl_pixel_format_new ( + babl_pixel_format_new ( "foo", babl_model ("grayscale"), babl_type ("float"), babl_component ("luminance"), NULL ), - (Babl*) babl_pixel_format_new ( + babl_pixel_format_new ( "bar", babl_model ("rgb"), babl_type ("float"), diff --git a/tests/rgb_to_lab_to_rgb.c b/tests/rgb_to_lab_to_rgb.c index 063a9fe..cf4c870 100644 --- a/tests/rgb_to_lab_to_rgb.c +++ b/tests/rgb_to_lab_to_rgb.c @@ -39,13 +39,13 @@ float destination_buf [PIXELS*3]; int test (void) { - BablFish *fish; - int i; - int OK=1; + Babl *fish; + int i; + int OK=1; fish = babl_fish ( - (Babl*) babl_pixel_format_new ( + babl_pixel_format_new ( "foo", babl_model ("rgb"), babl_type ("float"), @@ -54,7 +54,7 @@ test (void) babl_component ("blue"), NULL ), - (Babl*) babl_pixel_format_new ( + babl_pixel_format_new ( "bar", babl_model ("CIE Lab"), babl_type ("float"), @@ -67,8 +67,8 @@ test (void) babl_fish_process (fish, source_buf, temp_buf, PIXELS); - fish = babl_fish ((Babl*) babl_pixel_format ("bar"), - (Babl*) babl_pixel_format ("foo")); + fish = babl_fish (babl_pixel_format ("bar"), + babl_pixel_format ("foo")); babl_fish_process (fish, temp_buf, destination_buf, PIXELS); diff --git a/tests/rgb_to_ycbcr.c b/tests/rgb_to_ycbcr.c index a406457..8462067 100644 --- a/tests/rgb_to_ycbcr.c +++ b/tests/rgb_to_ycbcr.c @@ -47,13 +47,12 @@ float destination_buf [PIXELS*3]; int test (void) { - BablFish *fish; - int i; - int OK=1; - + Babl *fish; + int i; + int OK=1; fish = babl_fish ( - (Babl*) babl_pixel_format_new ( + babl_pixel_format_new ( "foo", babl_model ("rgb"), babl_type ("float"), @@ -62,7 +61,7 @@ test (void) babl_component ("blue"), NULL ), - (Babl*) babl_pixel_format_new ( + babl_pixel_format_new ( "bar", babl_model ("ycbcr"), babl_type ("float"), diff --git a/tests/rgb_to_ycbcr_to_rgb.c b/tests/rgb_to_ycbcr_to_rgb.c index e9a0d1d..4b324d2 100644 --- a/tests/rgb_to_ycbcr_to_rgb.c +++ b/tests/rgb_to_ycbcr_to_rgb.c @@ -39,13 +39,12 @@ float destination_buf [PIXELS*3]; int test (void) { - BablFish *fish; - int i; - int OK=1; - + Babl *fish; + int i; + int OK=1; fish = babl_fish ( - (Babl*) babl_pixel_format_new ( + babl_pixel_format_new ( "foo", babl_model ("rgb"), babl_type ("float"), @@ -54,7 +53,7 @@ test (void) babl_component ("blue"), NULL ), - (Babl*) babl_pixel_format_new ( + babl_pixel_format_new ( "bar", babl_model ("ycbcr"), babl_type ("float"), @@ -67,8 +66,8 @@ test (void) babl_fish_process (fish, source_buf, temp_buf, PIXELS); - fish = babl_fish ((Babl*) babl_pixel_format ("bar"), - (Babl*) babl_pixel_format ("foo")); + fish = babl_fish (babl_pixel_format ("bar"), + babl_pixel_format ("foo")); babl_fish_process (fish, temp_buf, destination_buf, PIXELS); diff --git a/tests/u8_to_float.c b/tests/u8_to_float.c index ca77219..e221021 100644 --- a/tests/u8_to_float.c +++ b/tests/u8_to_float.c @@ -31,20 +31,20 @@ float float_buf [BUFFER_LENGTH]; int test (void) { - BablFish *fish; - int i; - int OK=1; + Babl *fish; + int i; + int OK=1; fish = babl_fish ( - (Babl*) babl_pixel_format_new ( + babl_pixel_format_new ( "foo", babl_model ("grayscale"), babl_type ("u8"), babl_component ("luminance"), NULL ), - (Babl*) babl_pixel_format_new ( + babl_pixel_format_new ( "bar", babl_model ("grayscale"), babl_type ("float"), -- 2.30.2